﻿Imports MbUnit.Framework
Imports FM.NetBouncer

<TestFixture()> _
Public Class ParameterFixture
    <Test()> _
    Public Sub SetValue()

        Dim TestParam As New BaseParameter(Of String, Integer)("15", RuleSets.IntegerSet)
        Assert.IsTrue(TestParam.IsValid)

        'Change value now should invalidate
        TestParam.SetValue("a")

        Assert.IsFalse(TestParam.IsValid)

    End Sub

    <Test()> _
    Public Sub SetValueIntegerParameter()

        Dim TestParam As New IntegerParameter("15", RuleSets.IntegerSet)
        Assert.IsTrue(TestParam.IsValid)

        'Change value now should invalidate
        TestParam.SetValue("a")

        Assert.IsFalse(TestParam.IsValid)

    End Sub

    <Test()> _
    Public Sub RuleChanges()

        Dim TestParam As New BaseParameter(Of String, Integer)("15", RuleSets.IntegerSet)
        Assert.IsTrue(TestParam.IsValid)

        'Wrong RuleSet
        Dim NegativeSet As New RuleSet(Of String)
        NegativeSet.Rules.Add(New Rules.IsNegativeInteger)

        'Change ruleset now should invalidate
        TestParam.RuleSet = NegativeSet
        Assert.IsFalse(TestParam.IsValid)

    End Sub


    <Test()> _
    Public Sub RuleChangesWithIntegerParam()

        Dim TestParam As New IntegerParameter("15", RuleSets.IntegerSet)
        Assert.IsTrue(TestParam.IsValid)

        'Wrong RuleSet
        Dim NegativeSet As New RuleSet(Of String)
        NegativeSet.Rules.Add(New Rules.IsNegativeInteger)

        'Change ruleset now should invalidate
        TestParam.RuleSet = NegativeSet
        Assert.IsFalse(TestParam.IsValid)

    End Sub

    <Test("Constructor Test")> _
    Public Sub BaseParameter()
        Dim X As New BaseParameter(Of String, String)
    End Sub

    <Test("Double Escape Exception")> _
    <ExpectedException(GetType(System.Security.SecurityException))> _
    Public Sub DoubleEscapeException()

        Dim ModifierRules As New RuleSet(Of String)
        ModifierRules.Modifiers.Add(New Modifiers.HTML)

        Dim Param As New Parameter("<x>", ModifierRules)


        Param.EscapeTo(New Modifiers.HTML, False)


    End Sub

    <Test("Single Escape - Valid")> _
    Public Sub SingleEscape()

        Dim ModifierRules As New RuleSet(Of String)
        Dim Param As New Parameter("<x>", ModifierRules)

        Param.EscapeTo(New Modifiers.HTML, False)
    End Sub


    <Test("Forcing Escape - Double Negative Escape Exception")> _
    <ExpectedException(GetType(System.Security.SecurityException))> _
    Public Sub DoubleEscapeExceptionForce()

        Dim ModifierRules As New RuleSet(Of String)
        ModifierRules.Modifiers.Add(New Modifiers.HTML)

        Dim Param As New Parameter("<x>", ModifierRules)


        Param.EscapeTo(New Modifiers.HTML, False)


    End Sub


    <Test("Forcing Escape ")> _
  Public Sub ForcingEscape()

        Dim ModifierRules As New RuleSet(Of String)
        ModifierRules.Modifiers.Add(New Modifiers.HTML)

        Dim Param As New Parameter("<x>", ModifierRules)


        Param.EscapeTo(New Modifiers.HTML, True)

    End Sub




End Class
